/**
 * Created by Administrator on 2017/12/19.
 */
import cookie from "js-cookie";
import { Toast } from 'antd-mobile';
import { routerRedux } from 'dva/router';
import { dreview } from '../../services/organization';

export default {
  namespace: 'dreviews',
  state: {
    dreviewLists:[],
  },
  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(({pathname, query}) => {
        if(pathname === '/work/democraticappraisal') {
          dispatch({
            type:'fetch',
          })
        }
      })
    }
  },

  effects: {
    *fetch({payload}, { call, put, select }) {
      if(payload) {
        const data = yield call(dreview, payload);
        if (data.data.code == 200) {
          yield put({
            type: 'success',
            payload: {
              dreviewLists: data
            }
          });
          if (data.data.ret.length < 1) {
            Toast.fail("没有记录", 1);
          }
        }
        else {
          Toast.success('查询失败！', 1);
        }
      }
    },
  },

  reducers: {
    success(state, action){
      return {...state, ...action.payload};
    }
  }
};
